home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / flight-of-the-museum.swf / scripts / com / google / analytics / core / Utils.as < prev   
Encoding:
Text File  |  2011-10-17  |  2.2 KB  |  85 lines

  1. package com.google.analytics.core
  2. {
  3.    public class Utils
  4.    {
  5.        
  6.       
  7.       public function Utils()
  8.       {
  9.          super();
  10.       }
  11.       
  12.       public static function trim(raw:String, everything:Boolean = false) : String
  13.       {
  14.          var i:int = 0;
  15.          var iLeft:int = 0;
  16.          var iRight:int = 0;
  17.          if(raw == "")
  18.          {
  19.             return "";
  20.          }
  21.          var whitespaces:Array = [" ","\n","\r","\t"];
  22.          var str:String = raw;
  23.          if(everything)
  24.          {
  25.             i = 0;
  26.             while(i < whitespaces.length && str.indexOf(whitespaces[i]) > -1)
  27.             {
  28.                str = str.split(whitespaces[i]).join("");
  29.                i++;
  30.             }
  31.          }
  32.          else
  33.          {
  34.             iLeft = 0;
  35.             while(iLeft < str.length && whitespaces.indexOf(str.charAt(iLeft)) > -1)
  36.             {
  37.                iLeft++;
  38.             }
  39.             str = str.substr(iLeft);
  40.             iRight = str.length - 1;
  41.             while(iRight >= 0 && whitespaces.indexOf(str.charAt(iRight)) > -1)
  42.             {
  43.                iRight--;
  44.             }
  45.             str = str.substring(0,iRight + 1);
  46.          }
  47.          return str;
  48.       }
  49.       
  50.       public static function generateHash(input:String) : int
  51.       {
  52.          var pos:int = 0;
  53.          var current:int = 0;
  54.          var hash:* = 1;
  55.          var leftMost7:* = 0;
  56.          if(input != null && input != "")
  57.          {
  58.             hash = 0;
  59.             for(pos = input.length - 1; pos >= 0; pos--)
  60.             {
  61.                current = input.charCodeAt(pos);
  62.                hash = (hash << 6 & 268435455) + current + (current << 14);
  63.                leftMost7 = hash & 266338304;
  64.                if(leftMost7 != 0)
  65.                {
  66.                   hash ^= leftMost7 >> 21;
  67.                }
  68.             }
  69.          }
  70.          return hash;
  71.       }
  72.       
  73.       public static function generate32bitRandom() : int
  74.       {
  75.          return Math.round(Math.random() * 2147483647);
  76.       }
  77.       
  78.       public static function validateAccount(account:String) : Boolean
  79.       {
  80.          var rel:RegExp = /^UA-[0-9]*-[0-9]*$/;
  81.          return rel.test(account);
  82.       }
  83.    }
  84. }
  85.